package org.an.demo.test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.an.demo.MyApplication;

/**
 * Created by Fcy on 2015/12/13.<br/>
 */
public class RawUtils {

  public static String getString(int rawId) {
    InputStream inputStream = MyApplication.getInstance().getResources().openRawResource(rawId);
    return readStream(inputStream);
  }

  private static String readStream(InputStream is) {

    try {
      ByteArrayOutputStream bo = new ByteArrayOutputStream();
      int i = is.read();
      while (i != -1) {
        bo.write(i);
        i = is.read();
      }

      return bo.toString();
    } catch (IOException e) {
      return "";
    }
  }
}
